package com.gtw;

import com.gtw.composite.Component;
import com.gtw.composite.Composite;
import com.gtw.composite.Leaf;

public class Client {

    public static void main(String[] args){
        //创建根节点
        Composite root = new Composite();
        //创建树枝结构
        Composite branch = new Composite();
        //创建叶子节点
        Leaf leaf = new Leaf();
        //建立整体
        branch.add(leaf);
        root.add(branch);
        display(root);
    }

    /**
     * 递归向下遍历树
     */
    public static void display(Composite root){
        for(Component component: root.getChildren()){
            if(component instanceof Leaf){
                component.doSomething();
            }else {
                component.doSomething();
                display((Composite) component);
            }
        }
    }

    /**
     * 递归向上遍历
     * @param component
     */
    public static void find(Component component){

    }
}
